﻿<%@ WebHandler Language="C#" Class="Product_Bill_AddEdit" %>

using System;
using System.Web;
using System.Web.SessionState;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;

public class Product_Bill_AddEdit : IHttpHandler, IRequiresSessionState{

    private string VerificationImgCode = "";
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        ArrayList Shopping_Cart_List = new ArrayList();
        int Bill_Id = Convert.ToInt32(context.Request.Params["Bill_Id"].ToString().Trim());

        
        
        /* 如果是用户来信，验证安全码 */
        if (Bill_Id != 0)
        {
            Utils.ShowEnd(context, -1);
        }
            /* 验证购物车是否过期 */
            if (context.Session["Shopping_Cart_List"] == null)
                Utils.ShowEnd(context, -7);
            
            Shopping_Cart_List = (ArrayList)context.Session["Shopping_Cart_List"];
            Shopping_Cart_List.Sort();
            
            VerificationImgCode = context.Request.Params["VerificationImgCode"].ToString().Trim();
            /* 验证码判断 */
            if (context.Session["VerificationImgCode"] == null  )
                Utils.ShowEnd(context, -3);
            if (VerificationImgCode.ToLower() != context.Session["VerificationImgCode"].ToString().ToLower())
                Utils.ShowEnd(context, -3);
            /* 防止页面回退重复提交数据,清理掉 */
            context.Session["VerificationImgCode"] = "Is Did!";
        



        string Bill_User_Name = context.Request.Params["Bill_User_Name"].ToString().Trim();
        string Bill_User_Phone = context.Request.Params["Bill_User_Phone"].ToString().Trim();
        string Bill_User_Address = context.Request.Params["Bill_User_Address"].ToString().Trim();
        string Bill_SendShops = context.Request.Params["Bill_SendShops"].ToString().Trim();
        string Bill_Status = context.Request.Params["Bill_Status"].ToString().Trim();
        //ArrayList Bill_Product_List = Shopping_Cart_List;
        string Bill_Inquiry_Id = context.Request.Params["Bill_Inquiry_Id"].ToString().Trim();
        string Bill_Count_List = context.Request.Params["Bill_Count_List"].ToString().Trim();
        int item_lang = Convert.ToInt32(context.Request.Params["item_lang"].ToString().Trim());
        double Bill_Price = Convert.ToDouble(context.Request.Params["Bill_Price"].ToString().Trim());

        string product_list = "";
        for (int i = 0; i < Shopping_Cart_List.Count; i++)
        {
            if (i == 0)
                product_list = Shopping_Cart_List[i].ToString();
            else
                product_list = product_list + "," + Shopping_Cart_List[i].ToString();
        }
        

        /* 数据完整性验证 */
        Verification verification = new Verification();

        Regex chr;
        chr = new Regex(verification.ValidatePhone);
        if (!chr.IsMatch(Bill_User_Phone))
            Utils.ShowEnd(context, -1);

        Bills bill = new Bills();
        int status = bill.AddEdit(Bill_Id, Bill_User_Name, Bill_User_Phone, Bill_User_Address, Bill_SendShops, Bill_Status, product_list, Bill_Inquiry_Id, item_lang, Bill_Count_List, Bill_Price);
        Utils.ShowEnd(context, status + "\n LIST:" + product_list + "\n C:" + Shopping_Cart_List.Count + "\n" + Shopping_Cart_List[0].ToString());
        
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}